package com.opoc.utils;

import com.opoc.properties.JwtProperties;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
  public static String getToken(Map<String, Object> claims){
    return Jwts.builder()
      .addClaims(claims)
      .signWith(JwtProperties.Signature, JwtProperties.TOKEN_SECRET_KEY)
      .setExpiration(new Date(System.currentTimeMillis() + JwtProperties.TokenKeepTime))
      .compact();
  }

  public static Claims parseToken(String Token){
    return Jwts.parser()
      .setSigningKey(JwtProperties.TOKEN_SECRET_KEY)
      .parseClaimsJws(Token)
      .getBody();
  }
}
